package com.project.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.project.bean.StaffBean;
import com.project.mapper.IStaffMapper;
import com.project.service.IStaffService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class StaffServiceImpl implements IStaffService {
    @Autowired
    private IStaffMapper mapper;

    @Override
    public IPage<StaffBean> findByItem(Integer pageNO, Integer startMoney, Integer endMoney, String position) {
        QueryWrapper<StaffBean> qw = new QueryWrapper<>();
        if (startMoney != null) {
            qw.ge("s_money", startMoney);
        }
        if (endMoney != null) {
            qw.le("s_money", endMoney);
        }
        if (position != null && position.length() != 0) {
            qw.like("s_position", position);
        }
        return mapper.selectPage(new Page<>(pageNO, 3), qw);
    }

    @Override
    public void add(StaffBean staffBean) {
        mapper.insert(staffBean);
    }

    @Override
    public void del(Integer id) {
        mapper.deleteById(id);
    }

    @Override
    public void update(Integer id, Integer money) {
        StaffBean staffBean = mapper.selectById(id);
        staffBean.setMoney(money);
        mapper.updateById(staffBean);
    }

    @Override
    public StaffBean findById(Integer id) {
        return mapper.selectById(id);
    }
}
